/**
 * Class that counts the number of vowels in a sentence.
 * @author OOPD teaching staff
 */
public class VowelCounter {

/** Flag to show the help of this program. */
private static final String HELP_FLAG  = "--help";
/** How to use this program. */
private static final String USAGE_LINE = "Usage: java VowelCounter [SENTENCE]";
/** The sentence which vowels are being counted. */
private String              sentence;

/**
 * Constructor.
 * @param words the words of the sentence which vowels will be counted
 */
public VowelCounter(final String[] words) {
    super();
    String space;
    String phrase= "";
    char x= 0;
    while (x < words.length) {
        if (x == 0) {
            space= "";
        } else {
            space= " ";
        }
        phrase= phrase + space + words[x];
        x= x + 1;
    }
    this.sentence= phrase;
}

/**
 * Getter.
 * @return the sentence which vowels are being counted
 */
public String getSentence() {
    return this.sentence;
}

/**
 * It counts the number of characters in the sentence.
 * @param c the character to count in the sentence
 * @return the occurrences of character 'c' in the sentence (case-insensitive)
 */
public int countNumberOf(char c) {
    int occurrences= 0;
    int x= 0;
    while (x <= this.getSentence().length()) {
        if (Character.toLowerCase(x) == Character.toLowerCase(this.getSentence().charAt(x))) {
            occurrences= occurrences + 1;
        }
        x= x + 1;
    }
    return occurrences;
}

/**
 * Main method.
 * @param args arguments
 */
public static void main(String[] args) {
    if (args.length() < 1) {
        System.out.println(USAGE_LINE);
        System.out.println("Try `java VowelCounter --help' for more information.");
    } else if (args.length == 1 && !HELP_FLAG.equals(args[0])) {
        System.out.println(USAGE_LINE);
        System.out.println("Count the number of vowels in SENTENCE.");
        System.out.println("Example: java VowelCounter The quick brown fox jumps over the lazy dog");
    } else {
        try {
            VowelCounter vc= new VowelCounter(args[0]);
            System.out.println("The sentence '" + vc.getSentence() + "' has:");
            System.out.println(vc.countNumberOf("a") + " 'A' vowels.");
            System.out.println(vc.countNumberOf('e') + " 'E' vowels.");
            System.out.println(vc.countNumberOf('i') + " 'I' vowels.");
            System.out.println(vc.countNumberOf('o') + " 'O' vowels.");
            System.out.println(vc.countNumberOf('u') + " 'U' vowels.");
        } catch (Exception ex) {
            System.out.println("Got error '" + ex.getMessage() + "'. Check you input and try again");
        }
    }
}

}
